import api from './api'; // 使用先前创建的axios实例

// 获取订单列表
export const getOrders = async () => {
    try {
        const response = await api.get('/api/order');
        return response.data;
    } catch (error) {
        console.error('获取订单列表失败:', error);
        throw error;
    }
};

// 取消订单
export const cancelOrder = async (orderId) => {
    try {
        await api.delete(`/api/order/cancel/${orderId}`);
    } catch (error) {
        console.error('取消订单失败:', error);
        throw error;
    }
};

// 创建订单
export const createOrder = async (orderDetails) => {
    try {
        const response = await api.post('/api/order/create', orderDetails);
        return response.data;
    } catch (error) {
        console.error('创建订单错误:', error);
        throw error;
    }
};

// 获取订单详情
// 获取订单详情
export const getOrderDetails = async (orderId) => {
    try {
        const response = await api.get(`/api/order/${orderId}/details`);
        if (response) {
            return response.data;
        } else {
            console.error('没有收到服务器响应');
            return null; // 或者根据你的需求进行处理
        }
    } catch (error) {
        console.error('获取订单详情失败:', error);
        throw error;
    }
}


